﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page contentType="text/html; charset=utf-8"%>
<%@ page import="com.Const"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>批量导入数据</title>
<script src="${pageContext.request.contextPath }/scripts/boot.js" type="text/javascript"></script>
 
 <script type="text/javascript" src="${pageContext.request.contextPath }/scripts/ajaxfileupload.js"></script>  
</head>
<body>
<fieldset>
<div style="width:100%;height:90px;">
 <form id="form1"  enctype="multipart/form-data" method="post" action="${pageContext.request.contextPath }/files.do?method=dofile">
  <div style="width:100%;height:33px;text-align:center">
  <table style="table-layout:fixed">
     <tr>
    	<td style="width:90px;text-align:right ">请选择文件:</td>
    	<td style="width:540px " colspan="3">
   		  <input style="width:100%" type="file" name="file" id="file"/>  
    	  <input name="eventid" class="mini-hidden"/>   
    	</td>    
     </tr>       
   </table>
   </div>
 </form>
    <div style="text-align:center;padding:10px;">
        <a class="mini-button" onclick="check"  style="width:60px;margin-right:20px;">检测</a> 
		<a class="mini-button" onclick="onOk" iconCls="icon-ok" style="width:60px;margin-right:20px;" id="ok" enabled="false">确定</a> 
		<a class="mini-button" iconCls="icon-remove" onclick="onReset" style="width:60px;margin-right:20px;">重置</a>
		<a class="mini-button" iconCls="icon-download" href="/<%=Const.project%>/page/AC01/upload/loadfile.jsp?fileName=excel.xlsx" style="width:90px;margin-right:20px;">模版下载</a> 
	</div>
</fieldset>
<div>	 
  <div id="datagrid1" class="mini-datagrid" style="width:100%;height:360px;" allowResize="true"
	   url="AC01.do?method=gettemp" idField="id" multiSelect="true" >
    <div property="columns">
	  <div type="indexcolumn" ></div>			     
	  <div field="aac003" width="100" headerAlign="center" allowSort="true">姓名</div>
	  <div field="aac004" width="80" headerAlign="center" allowSort="true" >性别</div>
	  <div field="aac058" width="80" headerAlign="center" allowSort="true" >证件类型</div>
	  <div field="aac002" width="150" headerAlign="center" allowSort="true">证件号</div>	   
	  <div field="execmsg" width="150" headerAlign="center" allowSort="true">导入信息</div>
	</div>
  </div>
</div>
 
<script type="text/javascript">
	mini.parse();
	var grid = mini.get("datagrid1"); 
	var form = new mini.Form("form1");
	function onOk() {
	  SaveData();
	  mini.get("ok").setEnabled(false);
	  form.clear();
	}
	function check(){
	   Onsubmit();  
	   
	}
	function check1(e){
	  mini.mask({el: document.body,cls: 'mini-mask-loading',html: '导入中...'});
	  $.ajax({
			url : "${pageContext.request.contextPath }/AC01.do?method=saveunitpl1",
			type : 'post',
			data : {data : e},
			cache : false,
			success : function(text) {
			mini.unmask();
			var ss=text.split(",");
			var eventid=ss[1];
			if(eventid.length>20){
			eventid=eventid.substring(eventid.length-22,eventid.length-6);
			}
			if(ss[0]=="0"){
			mini.get("ok").setEnabled(true);
			mini.alert(ss[2]+","+ss[3]);
			id=id.substring(id.length-22,id.length-6);
      	    grid.load({id: eventid});
			}else{
			mini.alert(ss[0]);
			grid.load({id: eventid});
			}				   							
			},
			error : function(jqXHR, textStatus, errorThrown) {
			  		mini.unmask();
					mini.alert(jqXHR.responseText);					
				}
			});	
	}
	function Onsubmit(){  
      var arrId=new Array(); 
      arrId[0] ="file" ;     	
      $.ajaxFileUpload({
      		url:"${pageContext.request.contextPath }/files.do?method=dofile",
            type : 'post',
            secureuri : false,
            fileElementId : arrId,
            dataType:"text",
            async:false,
            success: function (text) {
            if(text.indexOf("err")>-1){
            	mini.alert("文件格式不符");
            	return;
            }else if(text.indexOf("null")>-1){
              mini.alert("上传失败");
              return;
            }else if(text.indexOf("nofile")>-1){
              mini.alert("请选择上传文件");
              return;
            }else{
               check1(text);
               mini.getbyName("eventid").setValue(text);
            }   
           }          
       });                         
    }
	function SaveData() {
	
     mini.mask({el: document.body,cls: 'mini-mask-loading',html: '导入中...'});
      
	  var o = form.getData();							
	  var json = mini.encode([o]);		
	  $.ajax({
			url : "${pageContext.request.contextPath }/AC01.do?method=saveunitpl",
			type : 'post',
			data : {data : json},
			cache : false,
			success : function(text) {	
				if("0"== text){
				    mini.unmask();
					mini.alert("登记成功，社会保障卡号见导入信息！");
					grid.reload();
					search();
					 
				}else{
				    mini.unmask();
					mini.alert(text);
					search();
				}						   							
			},
			error : function(jqXHR, textStatus, errorThrown) {
			  		mini.unmask();
					mini.alert(jqXHR.responseText);					
				}
			});
		}
	function search(){          
      var id = mini.getbyName("eventid").getValue().trim();
      if(id.length>20){
      id=id.substring(id.length-22,id.length-6);
      }
      if(id!=""){
      	grid.load({id: id});
      	grid.sortBy("execmsg","desc");
      }
    }
	function onReset(){
	  grid.clearRows();
	  document.getElementById("file").value="";  
	  mini.get("ok").setEnabled(false);
	}
</script>
</body>
</html>





